package d3_com.itheima.map;

import java.util.*;

/**
 * Map集合遍历方式
 */
public class Test {
    public static void main(String[] args) {
        Map<String, Double> map = new HashMap<>();
        Map<String, Double> map2 = new LinkedHashMap<>();
        Map<String, Double> map3 = new TreeMap<>();

        map.put("蜘蛛精", 162.5);
        map.put("蜘蛛精", 169.5);
        map.put("紫霞", 165.5);
        map.put("至尊宝", 175.5);
        System.out.println(map);

        map2.put("蜘蛛精", 162.5);
        map2.put("蜘蛛精", 169.5);
        map2.put("紫霞", 165.5);
        map2.put("至尊宝", 175.5);
        System.out.println(map2);

        map3.put("蜘蛛精", 162.5);
        map3.put("蜘蛛精", 169.5);
        map3.put("紫霞", 165.5);
        map3.put("至尊宝", 175.5);
        System.out.println(map3);

        System.out.println("---------------------");

        //1.获取Map集合的全部键(键找值)
        Set<String> keys = map.keySet();
        //根据键遍历对应的值
        for (String key : keys) {
            double value = map.get(key);
            System.out.println(key + "----->" + value);
        }
        System.out.println("-------------------------");
        //2.遍历Map集合(键值对) Ctrl+Alt+V
        Set<Map.Entry<String, Double>> entries = map.entrySet();
        for (Map.Entry<String, Double> entry : entries) {
            String key = entry.getKey();
            double value = entry.getValue();
            System.out.println(key + "----->" + value);
        }
        System.out.println("-------------------------");
        //3.lambda遍历Map集合
        map.forEach((k,v)->System.out.println(k + "----->" + v));
    }
}
